package net.dnw.practicesummary.mvp.net;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import net.dnw.practicesummary.mvp.utils.ApiConstants;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2019/3/15 0015.
 */

public class RetrofitServiceManager extends BaseRetrofit{


    private Retrofit retrofit;
    public static RetrofitServiceManager mInstance;

    private RetrofitServiceManager() {
        super();
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();
        //在构造方法中完成对Retrofit接口的初始化
        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BASE_URL)
                .client(getClient())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }

    public static RetrofitServiceManager getInstance() {
        if (mInstance == null) {
            synchronized (RetrofitServiceManager.class) {
                if (mInstance == null) {
                    mInstance = new RetrofitServiceManager();
                }
            }
        }
        return mInstance;
    }

    public Retrofit getRetrofit() {
        return retrofit;
    }
}
